<template>
	<view>
		<view>

			<view class="head" style="display: flex;">
				<view>今日用水量(吨)</view>
				<view>{{useWater}}</view>
			</view>
			<view class="body">

				<view style="padding: 5px;">本月用水详情</view>
				<!-- 				<view>11</view> -->
				<view style="padding-top: 10px;">
					<waterChart></waterChart>
				</view>

				<view style="display: flex;justify-content: space-between;">
					<view style="margin: 5px;">年度总水费</view>
					<view style="margin: 5px;">{{yearWaterFee}}</view>

				</view>

			</view>

			<view class="tail">
				<u-button type="primary" style="border-radius: 10px;" @click="show = true">缴纳水费</u-button>
			</view>

		</view>

		<view>
			<u-popup :show="show" mode="center" @close="close" @open="open">
				<view style="width: 300px;height: 200px;" class="uppo">
					<view>
						<view style="padding-left: 35px;padding-top: 20px;">请输入缴纳金额</view>
						<view style="display: flex;padding-left: 45px;padding-top: 17px;"> $ <u-input placeholder="请输入"
								border="surround" v-model="waterFee"></u-input></view>
						<view style="display: flex;padding-left: 53px;padding-top: 14px;">
							<u-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
								<u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1"
									:key="index" :label="item.name" :name="item.name" @change="radioChange">
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view> <u-button text="确认" @click="insertWaterFeeFun"></u-button>
					</view>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import waterChart from "../../charts/waterChart.vue";
	import rechargeInfo from "@/api/campus/index.js"
	export default {
		components: {
			waterChart: waterChart, // 注册别名
		},

		data() {
			return {
				waterFee: 20,
				show: false,
				useWater: 0,
				yearWaterFee:0,
				// 基本案列数据
				radiolist1: [{
						name: '校园卡支付',
						disabled: false
					},
					{
						name: '其它支付',
						disabled: false
					}
				],
				radiovalue1: '校园卡支付',
			}
		},

		mounted() {
			this.getWater();
			this.getYearWaterFeeFun();
		},
		methods: {
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			async getWater() {
				let type = "水费";
				try {
					let responseUseWater = await rechargeInfo.getUsewater(type);
					console.log(responseUseWater.data)
					this.useWater = responseUseWater.data


				} catch (error) {

				}
			},
			async getYearWaterFeeFun(){
				try{
					let response =await rechargeInfo.getTotalYearFee("水费")
					this.yearWaterFee=response.data
				}catch(error){
					
				}
				
			},
			async insertWaterFeeFun() {
				try {
					let insertResponse = await rechargeInfo.insertWaterFee(this.waterFee)
					this.getWater();
					this.getYearWaterFeeFun();
					// 关闭弹框
					this.show = false;
				} catch (error) {


				}
			}
		}
	};
</script>

<style lang="scss">
	.head {
		display: flex;
		/* 垂直居中 */
		height: 60px;
		background-color: #e6f7ff;
		/* 浅蓝色 */
		margin: 10px;
		color: #1890ff;
		/* 设置字体颜色为蓝色 */
		justify-content: space-between;
		/* 两端对齐，元素分布在两侧 */
		border-radius: 10px;

	}

	.body {
		margin: 10px;
		border-radius: 10px;
		background-color: #f0f0f0;

	}

	.tail {
		margin-top: 20px;
		margin-left: 10px;
		margin-right: 10px;
	}

	.uppo {
		display: flex;
		flex-direction: column;
		/* 垂直排列 */
		justify-content: space-between;
		/* 上下均分分布 */
		border-radius: 8px;
	}

	.comfirm {
		border-top: 1px solid black;
		height: 50px;
		display: flex;
		justify-content: center;
		/* 水平居中 */
		align-items: center;
		/* 垂直居中 */
	}
</style>
